package com.pengbei.enshrine.common.utils;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.pengbei.enshrine.R;
import com.pengbei.enshrine.common.dialog.AgreementDialog;
import com.pengbei.enshrine.common.dialog.AgreementSureDialog;
import com.pengbei.enshrine.common.dialog.AppUpdateDialog;
import com.pengbei.enshrine.common.dialog.CommonDialog;
import com.pengbei.enshrine.common.dialog.PermissionIntroduceDialog;
import com.pengbei.enshrine.common.dialog.callback.AppUpdateCallBack;
import com.pengbei.enshrine.common.dialog.callback.CommonCallBack;
import com.pengbei.enshrine.common.dialog.callback.PermissionIntroduceCallBack;
import com.pengbei.enshrine.common.dialog.callback.PictureWayCallBack;
import com.pengbei.enshrine.network.bean.PermissionIntroduceModel;

import java.util.List;

public class DialogUtils {

    /**
     * app更新弹窗
     * */
    public static void showAppUpdateDialog(Activity activity, List<String> updatemsg, String updateType, AppUpdateCallBack appUpdateCallBack){
        if (activity.isFinishing()){
            return;
        }
        AppUpdateDialog dialog = new AppUpdateDialog(activity).builder().show(updatemsg,updateType,appUpdateCallBack);
        dialog.show();
    }

    /**
     * 协议弹窗
     * */
    public static void showAgreementDialog(Activity activity, AgreementDialog.AgreementCallBack agreementCallBack) {
        if (activity.isFinishing()){
            return;
        }
        AgreementDialog dialog = new AgreementDialog(activity);
        dialog.setAgreementCallBack(agreementCallBack);
        dialog.show();
    }

    /**
     * 协议确认弹窗
     * */
    public static void showAgreementSureDialog(Activity activity,AgreementSureDialog.AgreementSureCallBack agreementSureCallBack){
        if (activity.isFinishing()){
            return;
        }
        AgreementSureDialog dialog = new AgreementSureDialog(activity);
        dialog.setAgreementSureCallBack(agreementSureCallBack);
        dialog.show();
    }

    /**
     * 动态权限说明弹窗
     * */
    public static void showPermissionIntroduceDialog(Activity activity, List<PermissionIntroduceModel> list, final PermissionIntroduceCallBack permissionIntroduceCallBack){
        if (activity.isFinishing()){
            return;
        }
        PermissionIntroduceDialog dialog = new PermissionIntroduceDialog(activity).builder().show(list,permissionIntroduceCallBack);
        dialog.show();
    }

    /**
     * 公共确认取消弹窗
     * */
    public static void showCommonDialog(Activity activity, String title, String content, String sure, String cancal, CommonCallBack commonCallBack){
        if (activity.isFinishing()){
            return;
        }
        CommonDialog dialog = new CommonDialog(activity).builder().show(title, content, sure, cancal,commonCallBack);
        dialog.show();
    }

    /**
     * 选择图片上传方式对话框
     * */
    public static void showChoicePictureWay(Activity activity, PictureWayCallBack pictureWayCallBack){
        if (activity.isFinishing()){
            return;
        }
        BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(activity, R.style.myBottomSheetDialog);
        bottomSheetDialog.setContentView(R.layout.dialog_choicepictureway);
        bottomSheetDialog.setCanceledOnTouchOutside(true);

        TextView tv_cpw_photo = bottomSheetDialog.findViewById(R.id.tv_cpw_photo);
        TextView tv_cpw_album = bottomSheetDialog.findViewById(R.id.tv_cpw_album);
        TextView tv_cpw_cancal = bottomSheetDialog.findViewById(R.id.tv_cpw_cancal);

        if (tv_cpw_photo != null) {
            tv_cpw_photo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomSheetDialog.dismiss();
                    pictureWayCallBack.takePicture();
                }
            });
        }

        if (tv_cpw_album != null) {
            tv_cpw_album.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomSheetDialog.dismiss();
                    pictureWayCallBack.photoAlbum();
                }
            });
        }

        if (tv_cpw_cancal != null) {
            tv_cpw_cancal.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomSheetDialog.dismiss();
                    pictureWayCallBack.cancal();
                }
            });
        }

        bottomSheetDialog.show();
    }

}
